package anthology.daily_question._24_11;

import java.util.List;

//https://leetcode.cn/problems/snake-in-matrix/description/?envType=daily-question&envId=2024-11-21
public class _3248矩阵中的蛇 {
    class Solution {
        public int finalPositionOfSnake(int n, List<String> commands) {
            int ans = 0;
            for(String s : commands){
                if(s.charAt(0) == 'U')
                    ans -= n;
                if(s.charAt(0) == 'D')
                    ans += n;
                if(s.charAt(0) == 'R')
                    ans++;
                if(s.charAt(0) == 'L')
                    ans--;
            }
            return ans;
        }
    }
    class Solution2 {
        public int finalPositionOfSnake(int n, List<String> commands) {
            int i = 0;
            int j = 0;
            for (String s : commands) {
                switch (s.charAt(0)) {
                    case 'U' -> i--;
                    case 'D' -> i++;
                    case 'L' -> j--;
                    default  -> j++;
                }
            }
            return i * n + j;
        }
    }
}
